import static org.junit.Assert.*;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class DuckFactoryTest {
	private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
	private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();

	@Before
	public void setUpStreams() {
	    System.setOut(new PrintStream(outContent));
	    System.setErr(new PrintStream(errContent));
	}

	@After
	public void cleanUpStreams() {
	    System.setOut(null);
	    System.setErr(null);
	}
	
	@Test
	public void testCreateMallardDuck() {
		AbstractDuckFactory factory = new DuckFactory();
		
		Quackable mallardDuck = factory.createMallardDuck();
		mallardDuck.quack();
		String out = outContent.toString();
		assertEquals("Quack\n", out);

	}

	@Test
	public void testCreateRedheadDuck() {
		AbstractDuckFactory factory = new DuckFactory();
		
		Quackable redheadDuck = factory.createRedheadDuck();
		redheadDuck.quack();
		String out = outContent.toString();
		assertEquals("Quack\n", out);
	}

	@Test
	public void testCreateDuckCall() {
		AbstractDuckFactory factory = new DuckFactory();
		
		Quackable DuckCall = factory.createDuckCall();
		DuckCall.quack();
		String out = outContent.toString();
		assertEquals("Kwak\n", out);
	}

	@Test
	public void testCreateRubberDuck() {
		AbstractDuckFactory factory = new DuckFactory();
		
		Quackable RubberDuck = factory.createRubberDuck();
		RubberDuck.quack();
		String out = outContent.toString();
		assertEquals("Squeak\n", out);
	}

}
